package com.example.lemis.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.lemis.model.domain.Admin;
import com.example.lemis.model.domain.SysOperationLog;
import com.example.lemis.mapper.SysOperationLogMapper;
import com.example.lemis.model.dto.LogDTO;
import com.example.lemis.model.dto.LogQuery;
import com.example.lemis.model.dto.PageDTO;
import com.example.lemis.model.vo.AdminInfoVO;
import com.example.lemis.model.vo.LogVO;
import com.example.lemis.service.IAdminService;
import com.example.lemis.service.ISysOperationLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 管理操作数据 服务实现类
 * </p>
 *
 * @author lxp
 * @since 2025-06-24
 */
@AllArgsConstructor
@Service
public class SysOperationLogServiceImpl extends ServiceImpl<SysOperationLogMapper, SysOperationLog>
        implements ISysOperationLogService {
    private final SysOperationLogMapper logMapper;
    private final IAdminService iAdminService;

    @Override
    public Page<LogVO> queryPage(LogQuery query, PageDTO pageDTO) throws Exception {
        iAdminService.auth();
        Page<LogVO> page = new Page<>(pageDTO.getPageNo(), pageDTO.getPageSize());
        return logMapper.queryPage(query, page);
    }

    @Override
    public LogVO insertLog(LogDTO logDTO) throws Exception {
        AdminInfoVO admin = iAdminService.auth();
        logMapper.insertLog(logDTO, admin.getId());
        return logMapper.selectByIdWithDict(logDTO.getId());
    }
}
